#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void do_regular_work(char * PZ);
void setup();
int get_ticket(char * PZ);
void shut_down();
int release_ticket(char * PZ);
int test_ticket(char * PZ);
int main(int argc, char * argv[]){
    if (argc != 2){
        printf("Please input the key!\n");
        return 0;
    }
    char * PZ = argv[1];
    setup();
    if (get_ticket(PZ) != 0)
        exit(0);
    do_regular_work(PZ);
    release_ticket(PZ);
    shut_down();
}

void do_regular_work(char * PZ){
    printf("App A can use!\n");
    for (int i = 0; i < 6; i++){
        sleep(15);
        if (test_ticket(PZ) != 0){
            printf("License is expired, App A can't use now!\n");
            break;
        }
    }
}
